package com.jy.rhin.application.infra;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.api.upload.UploadAPI;
import com.jy.rhin.domain.document.template.CDADocumentTemplateService;
import com.jy.rhin.facade.infra.controller.dto.CDADocumentTemplateDto;
import com.jy.rhin.facade.infra.controller.dto.CDADocumentTemplateNodeDto;
import com.jy.rhin.facade.infra.controller.dto.ImportCDADocumentTemplateReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Service
public class DocumentTemplateEditApplicationService {

    @Resource
    CDADocumentTemplateService cdaDocumentTemplateService;
    @Resource
    UploadAPI uploadAPI;

    public Page<CDADocumentTemplateDto> pageCDADocumentTemplate(String key, Integer current, Integer size) {
        return cdaDocumentTemplateService.pageCDADocumentTemplate(key, current, size);
    }

    public CDADocumentTemplateNodeDto importCDADocumentTemplate(ImportCDADocumentTemplateReq req) throws Exception {
//        String aliNetwork = uploadAPI.getAliNetwork(req.getUrl());
//        req.setUrl(aliNetwork);
        req.setUrl(req.getUrl());
        CDADocumentTemplateNodeDto node = cdaDocumentTemplateService.importCDADocumentTemplate(req);
        return node;
    }

    public String previewCDADocumentTemplateByNodes(CDADocumentTemplateNodeDto req) {
        return cdaDocumentTemplateService.previewCDADocumentTemplateByNodes(req);
    }

    public void saveCDADocumentTemplate(CDADocumentTemplateDto req) throws Exception {
        cdaDocumentTemplateService.saveCDADocumentTemplate(req);
    }

    public CDADocumentTemplateDto getCDADocumentTemplate(Long id) {
        return cdaDocumentTemplateService.getCDADocumentTemplate(id);
    }

    public void deleteCDADocumentTemplate(Long id) {
        cdaDocumentTemplateService.deleteCDADocumentTemplate(id);
    }

    public String previewCDADocumentTemplate(Long id) {
        return cdaDocumentTemplateService.previewCDADocumentTemplate(id);
    }

    public void downloadCDADocumentTemplate(Long id, HttpServletResponse response) throws Exception {
        cdaDocumentTemplateService.downloadCDADocumentTemplate(id, response);
    }

}
